package com.kucowka.main;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.kucowka.db.entities.User;
import com.kucowka.db.service.UserService;

import java.net.URL;

/*import com.google.gdata.client.contacts.ContactsService;
import com.google.gdata.data.contacts.ContactEntry;
import com.google.gdata.data.contacts.ContactFeed;
import com.google.gdata.data.contacts.GroupMembershipInfo;
import com.google.gdata.data.extensions.Email;
import com.google.gdata.data.extensions.ExtendedProperty;
import com.google.gdata.data.extensions.Im;*/

public class MainApp {

	public static void main(String[] args) throws Exception {
		
		ApplicationContext appContext = 
		    	  new ClassPathXmlApplicationContext("config.xml");
		
		UserService userService = (UserService) appContext.getBean("UserService");
		
		User user = new User();
		user.setName("Adam");
		user.setEmail("ad@am.pl");
		
		System.out.println(user);
		
		userService.createUser(user);
		
		System.err.println(userService.listAllUsers().iterator().next());
		
		
		
		
		
		/*ContactsService myService = new ContactsService("exampleCo-exampleApp-1");
		myService.setUserCredentials("brzegi.kucowka@gmail.com", "robert87");
		
		URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/brzegi.kucowka@gmail.com/full");
		  ContactFeed resultFeed = myService.getFeed(feedUrl, ContactFeed.class);
		  // Print the results
		  System.out.println(resultFeed.getTitle().getPlainText());
		  for (int i = 0; i < resultFeed.getEntries().size(); i++) {
		    ContactEntry entry = resultFeed.getEntries().get(i);
		    System.out.println("\t" + entry.getTitle().getPlainText());

		    System.out.println("Email addresses:");
		    for (Email email : entry.getEmailAddresses()) {
		      System.out.print(" " + email.getAddress());
		      if (email.getRel() != null) {
		        System.out.print(" rel:" + email.getRel());
		      }
		      if (email.getLabel() != null) {
		        System.out.print(" label:" + email.getLabel());
		      }
		      if (email.getPrimary()) {
		        System.out.print(" (primary) ");
		      }
		      System.out.print("\n");
		    }

		    System.out.println("IM addresses:");
		    for (Im im : entry.getImAddresses()) {
		      System.out.print(" " + im.getAddress());
		      if (im.getLabel() != null) {
		        System.out.print(" label:" + im.getLabel());
		      }
		      if (im.getRel() != null) {
		        System.out.print(" rel:" + im.getRel());
		      }
		      if (im.getProtocol() != null) {
		        System.out.print(" protocol:" + im.getProtocol());
		      }
		      if (im.getPrimary()) {
		        System.out.print(" (primary) ");
		      }
		      System.out.print("\n");
		    }

		    System.out.println("Groups:");
		    for (GroupMembershipInfo group : entry.getGroupMembershipInfos()) {
		      String groupHref = group.getHref();
		      System.out.println("  Id: " + groupHref);
		    }

		    System.out.println("Extended Properties:");
		    for (ExtendedProperty property : entry.getExtendedProperties()) {
		      if (property.getValue() != null) {
		        System.out.println("  " + property.getName() + "(value) = " +
		            property.getValue());
		      } else if (property.getXmlBlob() != null) {
		        System.out.println("  " + property.getName() + "(xmlBlob)= " +
		            property.getXmlBlob().getBlob());
		      }
		    }

		    String photoLink = entry.getContactPhotoLink().getHref();
		    System.out.println("Photo Link: " + photoLink);

		    System.out.println("Contact's ETag: " + entry.getEtag());
		  }		*/
		
	}
}
